package com.jtny.nytb.equipment.vo.dataparam;

import cn.hutool.core.util.ObjectUtil;
import com.jtny.component.entity.BaseDTO;
import com.jtny.component.util.BeanUtils;
import com.jtny.nytb.config.datafactor.dto.ConfigAlgorithDTO;
import com.jtny.nytb.equipment.dto.dataparam.AlgorithmTempDTO;
import com.jtny.nytb.equipment.dto.dataparam.ParamTempDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 数据参量公式对象
 *
 * @author 智慧能源中心 - 伍天宇
 * @package com.jtny.nytb.energymonitor.equipment.vo.dataparam
 * @fileName ConfigAlgorithVO.java
 * @createTime 2023年09月20日 09:33
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@Data
@ApiModel("数据参量公式对象")
@NoArgsConstructor
@AllArgsConstructor
public class AlgorithmVO extends BaseDTO implements Serializable {

    @ApiModelProperty("算法公式id")
    private Long algorithmId;
    @ApiModelProperty("算法分类")
    private String algorithmType;
    @ApiModelProperty("算法名称")
    private String algorithmName;
    @ApiModelProperty("算法公式配置方案")
    private String algorithmConfigurationScheme;
    @ApiModelProperty("算法公式描述")
    private String algorithmDescription;
    @ApiModelProperty("算法计算公式")
    private String algorithmFormula;
    @ApiModelProperty("算法脚本路径")
    private String scriptPath;
    @ApiModelProperty("算法请求方式")
    private String requestType;
    @ApiModelProperty("算法小数点保留个数")
    private Integer algorithmAccuracyDigit;
    /**
     * 参数列表
     */
    @ApiModelProperty("参数列表")
    private List<ParamTempVO> configParamList;


    public ConfigAlgorithDTO buildDTO() {
        ConfigAlgorithDTO result = new ConfigAlgorithDTO();
        result.setAlgorithId(algorithmId);
        result.setAlgorithmType(algorithmType);
        result.setAlgorithName(algorithmName);
        result.setAlgorithConfigurationScheme(this.algorithmConfigurationScheme);
        result.setAlgorithDescription(algorithmDescription);
        result.setAlgorithFormula(algorithmFormula);
        result.setScriptPath(scriptPath);
        result.setRequestType(requestType);
        result.setAlgorithAccuracyDigit(algorithmAccuracyDigit);
        return result;
    }

    public AlgorithmTempDTO buildTempDTO() {
        AlgorithmTempDTO result = new AlgorithmTempDTO();
        result.setAlgorithmId(algorithmId);
        result.setAlgorithmName(algorithmName);
        result.setAlgorithmConfigurationScheme(this.algorithmConfigurationScheme);
        result.setAlgorithmDescription(algorithmDescription);
        result.setAlgorithmFormula(algorithmFormula);
        result.setScriptPath(scriptPath);
        result.setRequestType(requestType);
        result.setAlgorithmAccuracyDigit(algorithmAccuracyDigit);
        result.setParamTempList(BeanUtils.copyToList(configParamList, ParamTempDTO.class));
        return result;
    }

    public AlgorithmVO(ConfigAlgorithDTO dto) {
        if (ObjectUtil.isNull(dto)) {
            return;
        }
        this.algorithmId = dto.getAlgorithId();
        this.algorithmName = dto.getAlgorithName();
        this.algorithmConfigurationScheme = dto.getAlgorithConfigurationScheme();
        this.algorithmDescription = dto.getAlgorithDescription();
        this.algorithmFormula = dto.getAlgorithFormula();
        this.scriptPath = dto.getScriptPath();
        this.requestType = dto.getRequestType();
        this.algorithmAccuracyDigit = dto.getAlgorithAccuracyDigit();
    }

    public AlgorithmVO(AlgorithmTempDTO algorithm) {
        if (ObjectUtil.isNull(algorithm)) {
            return;
        }
        this.algorithmId = algorithm.getAlgorithmId();
        this.algorithmName = algorithm.getAlgorithmName();
        this.algorithmConfigurationScheme = algorithm.getAlgorithmConfigurationScheme();
        this.algorithmDescription = algorithm.getAlgorithmDescription();
        this.algorithmFormula = algorithm.getAlgorithmFormula();
        this.scriptPath = algorithm.getScriptPath();
        this.requestType = algorithm.getRequestType();
        this.algorithmAccuracyDigit = algorithm.getAlgorithmAccuracyDigit();
        this.configParamList = BeanUtils.copyToList(algorithm.getParamTempList(), ParamTempVO.class);
    }


}
